/*
 *  Copyright (C) 2010 Martin Haulrich <mwh.isv@cbs.dk> and Matthias Buch-Kromann <mbk.isv@cbs.dk>
 *
 *  This file is part of the IncrementalParser package.
 *
 *  The IncrementalParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.osdtsystem.incparser.data;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Martin Haulrich
 */
public class CONLLToken {
    public static final int ID = 0;
    public static final int FORM = 1;
    public static final int LEMMA = 2;
    public static final int CPOSTAG = 3;
    public static final int POSTAG = 4;
    public static final int FEATS = 5;
    public static final int HEAD = 6;
    public static final int DEPREL = 7;
    public static final int PHEAD = 8;
    public static final int PDEPREL = 9;
    public List<String> tokens;

    final static CONLLToken ROOT = rootToken();

    static CONLLToken rootToken() {
        List<String> rootTokens = new ArrayList<String>();
        rootTokens.add("<root>-id");
        rootTokens.add("<root>-form");
        rootTokens.add("<root>-lemma");
        rootTokens.add("<root>-cpos");
        rootTokens.add("<root>-pos");
        rootTokens.add("<root>-feats");
        rootTokens.add("<root>-head");
        rootTokens.add("<root>-deprel");
        rootTokens.add("<root>-phead");
        rootTokens.add("<root>-pdeprel");
        return new CONLLToken(rootTokens);
    }

    public CONLLToken(List<String> tokens) {
        this.tokens = tokens;
    }

    public String get(int type) {
        return tokens.get(type);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CONLLToken other = (CONLLToken) obj;
        if (this.tokens != other.tokens && (this.tokens == null || !this.tokens.equals(other.tokens))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 37 * hash + (this.tokens != null ? this.tokens.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (String s : tokens) {
            sb.append(s).append("\t");
        }
        return sb.toString().trim();
    }

    public String toString(int head, String depRel) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < HEAD; ++i)
            sb.append(tokens.get(i)).append("\t");
        sb.append(head).append("\t")
                .append(depRel).append("\t_\t_");
        return sb.toString().trim();
    }
}
